<?php
   define('ACC',true);
require_once('../include/init.php');

   if(isset($_POST['username']) && $_POST['username'] != '' ){
             $data = $_POST;
             $user = new userModel(); 
            // //自动过滤不是表单字段的数据
            //  $data = $user->shiftData($data);

            //验证登陆数据是否合法
            // if(!$user->_validate($data)){
            // 	$messge = $user->error();
            // };

            //查看数据库中是否有该条数据
            $request = $user->checkmsg($data['username'],$data['passwd']);
            if($request['username']){
            	$_SESSION['username'] =  $request['username'];
            	$_SESSION['user_id'] = $request['user_id'];
            	$_SESSION['email'] = $request['email'];
            	//设置cookie 默认有效时间两周

            	setcookie('username',$request['username'],time()+14*24*3600);
                $messge = '登陆成功';
                require_once('../view/front/messge.html');
            }else{
            	$messge = '用户名密码不匹配';
                require_once('../view/front/messge.html');
            }
         
   }else{
   	        $cookiename = isset($_COOKIE['username'])?$_COOKIE['username']:'';
       require_once('../view/front/denlu.html');
   	   
   	    
   	   
   }

?>